package com.fc.test.controller.admin;

import com.fc.test.common.base.BaseController;
import com.fc.test.model.custom.*;
import com.fc.test.service.UserService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * describe: 活动管理控制器
 *
 * @author xugang
 * @date 2018/9/21 10:12
 */
@Controller
@RequestMapping("EventsController")
@Api("活动管理")
public class EventsController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(EventsController.class);

    // 跳转页面参数
    private String prefix = "admin/event/";

    @Autowired
    private UserService userService;

    /**
     * 进入活动管理--用户信息查询页面
     *
     * @param model
     * @return
     */
    @RequestMapping("view")
    @RequiresPermissions("events:user:view")
    public String view(Model model) {
        logger.info("===>>> 进入活动管理页面, URL:[{}]", "/EventsController/view");
        setTitle(model, new TitleVo("活动用户列表", "活动管理", false, "欢迎进入活动页面", false, false));
        return prefix + "list";
    }

    /**
     * 活动用户列表
     *
     * @param tablepar
     * @param searchTxt
     * @return
     */
    @RequestMapping("list/user")
    @RequiresPermissions("events:user:list")
    @ResponseBody
    public Object list(Tablepar tablepar, String searchTxt) {
        PageInfo<TUser> page = userService.list(tablepar, searchTxt);
        TableSplitResult<TUser> result = new TableSplitResult<TUser>(page.getPageNum(), page.getTotal(), page.getList());
        return result;
    }

    //----------------------------------------------------------------------------------------------------------

    /**
     * 进入活动管理--中奖信息信息查询页面
     *
     * @param model
     * @return
     */
    @RequestMapping("prizeview")
    @RequiresPermissions("events:prize:view")
    public String view4turntable(Model model) {
        logger.info("===>>> 进入活动管理页面, URL:[{}]", "/EventsController/prizeview");
        setTitle(model, new TitleVo("活动中奖列表", "活动管理", false, "欢迎进入活动页面", false, false));
        return prefix + "prizelist";
    }

    /**
     * 活动中奖记录列表
     *
     * @param tablepar
     * @param searchTxt
     * @return
     */
    @RequestMapping("list/prize")
    @RequiresPermissions("events:prize:list")
    @ResponseBody
    public Object prizeList(Tablepar tablepar, String searchTxt) {
        PageInfo<TEventsTurntable> page = userService.list4turntable(tablepar, searchTxt);
        TableSplitResult<TEventsTurntable> result = new TableSplitResult<TEventsTurntable>(page.getPageNum(), page.getTotal(), page.getList());
        return result;
    }
}
